﻿using System;
using System.Collections;
using System.Windows.Forms;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Editors
{
    /// <summary>
    /// Sort the tree view.
    /// </summary>
    public class TreeViewSorter : IComparer
    {
        public int Compare(object x, object y)
        {
            TreeNode tx = x as TreeNode;
            if (tx == null)
                throw new NotSupportedException("x");

            TreeNode ty = y as TreeNode;
            if (ty == null)
                throw new NotSupportedException("y");


            if (tx.Tag is FolderPickerElement && ty.Tag is LeafPickerElement)
                return 0;

            if (tx.Tag is LeafPickerElement && ty.Tag is FolderPickerElement)
                return 1;

            return ((new CaseInsensitiveComparer()).Compare(tx.Text, ty.Text));
        }
    }
}
